package school;

public class Student extends Person {
    private int grade;
    private Course course;

    public Student(String studentId, String name, String gender, int grade) {
        super(studentId, name, gender);
        this.grade = grade;
    }

    // 选课方法（保持不变）
    public void selectCourse(Course course) {
        if (this.course != null) {
            System.out.println(name + "已有选课记录，需退课后重新选择！");
            return;
        }
        this.course = course;
        System.out.println(grade + "级" + name + "选择了课程《" + course.getCourseName() + "》");
    }

    // 退课方法（保持不变）
    public void dropCourse() {
        if (course != null) {
            System.out.println(name + "退选了课程《" + course.getCourseName() + "》");
            this.course = null;
        } else {
            System.out.println(name + "当前无选课记录，无法退课！");
        }
    }

    // 重写打印方法，添加学生特有信息
    @Override
    public void printInfo() {
        super.printInfo(); // 调用父类方法打印基本信息
        System.out.println("年级：" + grade + "级");
        System.out.println("=== 选课信息 ===");
        if (course != null) {
            System.out.println("课程名称：《" + course.getCourseName() + "》");
            System.out.println("上课时间：" + course.getTime());
            System.out.println("授课教师：" + course.getTeacher().getName());
        } else {
            System.out.println("当前无选课记录");
        }
        System.out.println("===================\n");
    }
}